home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / comms / other / micq-0.4.0 / util.c < prev    next >
C/C++ Source or Header  |  1999-05-14  |  26KB  |  823 lines

  1. /*********************************************
  2. **********************************************
  3. This is a file of general utility functions useful
  4. for programming in general and icq in specific
  5.  
  6. This software is provided AS IS to be used in
  7. whatever way you see fit and is placed in the
  8. public domain.
  9.  
  10. Author : Matthew Smith April 23, 1998
  11. Contributors :  airog (crabbkw@rose-hulman.edu) May 13, 1998
  12.  
  13.  
  14. Changes :
  15.   6-18-98 Added support for saving auto reply messages. Fryslan
  16.  
  17. **********************************************
  18. **********************************************/
  19. #include "micq.h"
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <stdarg.h>
  23. #include <assert.h>
  24. #include <string.h>
  25. #include <ctype.h>
  26. #include <errno.h>
  27. #include <time.h>
  28. #include <sys/types.h>
  29. #include <sys/time.h>
  30. #include <sys/stat.h>
  31. #include <netinet/in.h>
  32. #include <arpa/inet.h>
  33. #include <fcntl.h>
  34. #ifdef _WIN32
  35.    #include <io.h>
  36.    #define S_IRUSR        _S_IREAD
  37.    #define S_IWUSR        _S_IWRITE
  38. #endif
  39. #ifdef UNIX
  40.    #include <unistd.h>
  41.    #include <termios.h>
  42.    #include "mreadline.h"
  43. #endif
  44. #ifdef __SASC
  45. #include <proto/dos.h>
  46. #include "amiga-dt.h"
  47. #endif
  48.  
  49. #ifdef UNIX
  50. char *strdup( const char * );
  51. int strcasecmp( const char *, const char * );
  52. int strncasecmp( const char *, const char *, size_t );
  53. #endif
  54.  
  55. typedef struct 
  56. {
  57.    const char *name;
  58.    WORD code;
  59. } COUNTRY_CODE;
  60.  
  61.  
  62. static COUNTRY_CODE Country_Codes[] = { { USA_COUNTRY_STR, 1 },
  63.                                  { Afghanistan_COUNTRY_STR, 93 },
  64.                                  { Albania_COUNTRY_STR, 355 },
  65.                                  { Algeria_COUNTRY_STR, 213 },
  66.                                  { American_Samoa_COUNTRY_STR, 684 },
  67.                                  { Andorra_COUNTRY_STR, 376 },
  68.                                  { Angola_COUNTRY_STR, 244 },
  69.                                  { Anguilla_COUNTRY_STR, 101 },
  70.                                  { Antigua_COUNTRY_STR, 102 },
  71.                                  { Argentina_COUNTRY_STR, 54 },
  72.                                  { Armenia_COUNTRY_STR, 374 },
  73.                                  { Aruba_COUNTRY_STR, 297 },
  74.                                  { Ascention_Island_COUNTRY_STR, 274 },
  75.                                  { Australia_COUNTRY_STR, 61 },
  76.                                  { Australian_Antartic_Territory_COUNTRY_STR, 6721 },
  77.                                  { Austria_COUNTRY_STR, 43 },
  78.                                  { Azerbaijan_COUNTRY_STR, 934 },
  79.                                  { Bahamas_COUNTRY_STR, 103 },
  80.                                  { Bahrain_COUNTRY_STR, 973 },
  81.                                  { Bangladesh_COUNTRY_STR, 880 },
  82.                                  { Barbados_COUNTRY_STR, 104 },
  83.                                  { Belarus_COUNTRY_STR, 375 },
  84.                                  { Belgium_COUNTRY_STR, 32 },
  85.                                  { Belize_COUNTRY_STR, 501 },
  86.                                  { Benin_COUNTRY_STR, 229 },
  87.                                  { Bermuda_COUNTRY_STR, 105 },
  88.                                  { Bhutan_COUNTRY_STR, 975 },
  89.                                  { Bolivia_COUNTRY_STR, 591 },
  90.                                  { Bosnia_Herzegovina_COUNTRY_STR, 387 },
  91.                                  { Botswana_COUNTRY_STR, 267 },
  92.                                  { Brazil_COUNTRY_STR, 55 },
  93.                                  { British_Virgin_Islands_COUNTRY_STR, 106 },
  94.                                  { Brunei_COUNTRY_STR, 673 },
  95.                                  { Bulgaria_COUNTRY_STR, 359 },
  96.                                  { Burkina_Faso_COUNTRY_STR, 226 },
  97.                                  { Burundi_COUNTRY_STR, 257 },
  98.                                  { Cambodia_COUNTRY_STR, 855 },
  99.                                  { Cameroon_COUNTRY_STR, 237 },
  100.                                  { Canada_COUNTRY_STR, 107 },
  101.                                  { Cape_Verde_Islands_COUNTRY_STR, 238 },
  102.                                  { Cayman_Islands_COUNTRY_STR, 108},
  103.                                  { Central_African_Republic_COUNTRY_STR, 236},
  104.                                  { Chad_COUNTRY_STR, 235},
  105.                                  { Christmas_Island_COUNTRY_STR, 672},
  106.                                  { Cocos_Keeling_Islands_COUNTRY_STR, 6101},
  107.                                  { Comoros_COUNTRY_STR, 2691},
  108.                                  { Congo_COUNTRY_STR, 242},
  109.                                  { Cook_Islands_COUNTRY_STR, 682},
  110.                                  { Chile_COUNTRY_STR, 56 },
  111.                                  { China_COUNTRY_STR, 86 },
  112.                                  { Columbia_COUNTRY_STR, 57 },
  113.                                  { Costa_Rice_COUNTRY_STR, 506 },
  114.                                  { Croatia_COUNTRY_STR, 385 }, /* Observerd */
  115.                                  { Cuba_COUNTRY_STR, 53 },
  116.                                  { Cyprus_COUNTRY_STR, 357 },
  117.                                  { Czech_Republic_COUNTRY_STR, 42 },
  118.                                  { Denmark_COUNTRY_STR, 45 },
  119.                                  { Diego_Garcia_COUNTRY_STR, 246},
  120.                                  { Djibouti_COUNTRY_STR, 253},
  121.                                  { Dominica_COUNTRY_STR, 109},
  122.                                  { Dominican_Republic_COUNTRY_STR, 110},
  123.                                  { Ecuador_COUNTRY_STR, 593 },
  124.                                  { Egypt_COUNTRY_STR, 20 },
  125.                                  { El_Salvador_COUNTRY_STR, 503 },
  126.                                  { Equitorial_Guinea_COUNTRY_STR, 240},
  127.                                  { Eritrea_COUNTRY_STR, 291},
  128.                                  { Estonia_COUNTRY_STR, 372},
  129.                                  { Ethiopia_COUNTRY_STR, 251 },
  130.                                  { Former_Yugoslavia_COUNTRY_STR, 389},
  131.                                  { Faeroe_Islands_COUNTRY_STR, 298},
  132.                                  { Falkland_Islands_COUNTRY_STR, 500},
  133.                                  { Federated_States_of_Micronesia_COUNTRY_STR, 691 },
  134.                                  { Fiji_COUNTRY_STR, 679 },
  135.                                  { Finland_COUNTRY_STR, 358 },
  136.                                  { France_COUNTRY_STR, 33 },
  137.                                  { French_Antilles_COUNTRY_STR, 596 },  /* Leave it */
  138.                                  { French_Antilles_COUNTRY_STR, 5901 }, /* Either on or the other is right :) */
  139.                                  { French_Guiana_COUNTRY_STR, 594 },
  140.                                  { French_Polynesia_COUNTRY_STR, 689 },
  141.                                  { Gabon_COUNTRY_STR, 241 },
  142.                                  { Gambia_COUNTRY_STR, 220 },
  143.                                  { Georgia_COUNTRY_STR, 995 },
  144.                                  { Germany_COUNTRY_STR, 49 },
  145.                                  { Ghana_COUNTRY_STR, 233 },
  146.                                  { Gibraltar_COUNTRY_STR, 350 },
  147.                                  { Greece_COUNTRY_STR, 30 },
  148.                                  { Greenland_COUNTRY_STR, 299 },
  149.                                  { Grenada_COUNTRY_STR, 111 },
  150.                                  { Guadeloupe_COUNTRY_STR, 590 },
  151.                                  { Guam_COUNTRY_STR, 671 },
  152.                                  { Guantanomo_Bay_COUNTRY_STR, 5399 },
  153.                                  { Guatemala_COUNTRY_STR, 502 },
  154.                                  { Guinea_COUNTRY_STR, 224 },
  155.                                  { Guinea_Bissau_COUNTRY_STR, 245 },
  156.                                  { Guyana_COUNTRY_STR, 592 },
  157.                                  { Haiti_COUNTRY_STR, 509 },
  158.                                  { Honduras_COUNTRY_STR, 504 },
  159.                                  { Hong_Kong_COUNTRY_STR, 852 },
  160.                                  { Hungary_COUNTRY_STR, 36 },
  161.                                  { Iceland_COUNTRY_STR, 354 },
  162.                                  { India_COUNTRY_STR, 91 },
  163.                                  { Indonesia_COUNTRY_STR, 62 },
  164.                                  { INMARSAT_COUNTRY_STR, 870 },
  165.